export const dateFormat = (date: Date | number | string, format?: string) => {
  if (typeof date === 'number' || typeof date === 'string') {
    const dateStr = String(date)
    if ('YYYY-MM-DD' === format) {
      return `${dateStr.slice(0, 4)}-${dateStr.slice(4, 6)}-${dateStr.slice(6, 8)}`
    } else if ('YYYYMMDD' === format) {
      return `${dateStr.slice(0, 4)}${dateStr.slice(4, 6)}${dateStr.slice(6, 8)}`
    } else if ('YYYY/MM/DD' === format) {
      return `${dateStr.slice(0, 4)}/${dateStr.slice(4, 6)}/${dateStr.slice(6, 8)}`
    } else {
      return `${dateStr.slice(0, 4)}${dateStr.slice(4, 6)}${dateStr.slice(6, 8)}`
    }
  }

  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')

  if ('YYYY-MM-DD' === format) {
    return `${year}-${month}-${day}`
  } else if ('YYYYMMDD' === format) {
    return `${year}${month}${day}`
  } else if ('YYYY/MM/DD' === format) {
    return `${year}/${month}/${day}`
  } else {
    return `${year}${month}${day}`
  }
}
